#!/usr/bin/perl

use warnings;
use File::Find;

my $count  = 0;
my $tmpDir = "";
my $dstDir = $ARGV[0];
print "Will operate on " . $dstDir . "\n\n";

find( \&wanted, $dstDir );

sub want
{
	print "\n\$File::Find::dir = $File::Find::dir\n";
	print "\$_ = $_\n";
	print "\$File::Find::name = $File::Find::name\n";

	#we should judge the target whether a dir or not using $_, NOT
	#using $File::Find::name, since we have chdir to the target.
	if ( -d $_ )
	{
		print "$File::Find::name is a dir.\n";
	}
	else
	{
		print "$File::Find::name is NOT a dir.\n";
	}
}

sub wanted
{

	# $File::Find::dir  is the current directory name,
	# $_ is the current filename within that directory
	# $File::Find::name is the complete pathname to the file.
	return if /^\./    #omit . .. and hidden files
		  || $File::Find::name =~ /CVS/    #omit CVS dir
		  || $File::Find::name =~ /SVN/    #omit SVN dir
		  || -d $_;                        #omit subdirectoy

	if ( $tmpDir ne $File::Find::dir )
	{
		$tmpDir = $File::Find::dir;
		print "\n===== current dir: [$tmpDir] =====\n";
	}

	$count++;
	print "$count:\t$_\n";
	`dos2unix $_`;
}
